home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Modifier.java < prev    next >
Text File  |  1998-09-22  |  5KB  |  168 lines

  1. /*
  2.  * @(#)Modifier.java    1.6 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang.reflect;
  16.  
  17. /**
  18.  * The Modifier class provides static methods and constants to decode
  19.  * class and member access modifiers.
  20.  *
  21.  * @see Class#getModifiers()
  22.  * @see Member#getModifiers()
  23.  *
  24.  * @author Nakul Saraiya
  25.  */
  26. public
  27. class Modifier {
  28.  
  29.     /**
  30.      * Return true if the specified integer includes the <tt>public</tt>
  31.      * modifier.
  32.      */
  33.     public static boolean isPublic(int mod) {
  34.     return (mod & PUBLIC) != 0;
  35.     }
  36.  
  37.     /**
  38.      * Return true if the specifier integer includes the <tt>private</tt>
  39.      * modifier.
  40.      */
  41.     public static boolean isPrivate(int mod) {
  42.     return (mod & PRIVATE) != 0;
  43.     }
  44.  
  45.     /**
  46.      * Return true if the specifier integer includes the <tt>protected</tt>
  47.      * modifier.
  48.      */
  49.     public static boolean isProtected(int mod) {
  50.     return (mod & PROTECTED) != 0;
  51.     }
  52.  
  53.     /**
  54.      * Return true if the specifier integer includes the <tt>static</tt>
  55.      * modifier.
  56.      */
  57.     public static boolean isStatic(int mod) {
  58.     return (mod & STATIC) != 0;
  59.     }
  60.  
  61.     /**
  62.      * Return true if the specifier integer includes the <tt>final</tt>
  63.      * modifier.
  64.      */
  65.     public static boolean isFinal(int mod) {
  66.     return (mod & FINAL) != 0;
  67.     }
  68.  
  69.     /**
  70.      * Return true if the specifier integer includes the <tt>synchronized</tt>
  71.      * modifier.
  72.      */
  73.     public static boolean isSynchronized(int mod) {
  74.     return (mod & SYNCHRONIZED) != 0;
  75.     }
  76.  
  77.     /**
  78.      * Return true if the specifier integer includes the <tt>volatile</tt>
  79.      * modifier.
  80.      */
  81.     public static boolean isVolatile(int mod) {
  82.     return (mod & VOLATILE) != 0;
  83.     }
  84.  
  85.     /**
  86.      * Return true if the specifier integer includes the <tt>transient</tt>
  87.      * modifier.
  88.      */
  89.     public static boolean isTransient(int mod) {
  90.     return (mod & TRANSIENT) != 0;
  91.     }
  92.  
  93.     /**
  94.      * Return true if the specifier integer includes the <tt>native</tt>
  95.      * modifier.
  96.      */
  97.     public static boolean isNative(int mod) {
  98.     return (mod & NATIVE) != 0;
  99.     }
  100.  
  101.     /**
  102.      * Return true if the specifier integer includes the <tt>interface</tt>
  103.      * modifier.
  104.      */
  105.     public static boolean isInterface(int mod) {
  106.     return (mod & INTERFACE) != 0;
  107.     }
  108.  
  109.     /**
  110.      * Return true if the specifier integer includes the <tt>abstract</tt>
  111.      * modifier.
  112.      */
  113.     public static boolean isAbstract(int mod) {
  114.     return (mod & ABSTRACT) != 0;
  115.     }
  116.  
  117.     /**
  118.      * Return a string describing the access modifier flags in
  119.      * the specified modifier. For example:
  120.      * <pre>
  121.      *    public final synchronized
  122.      *    private transient volatile
  123.      * </pre>
  124.      * The modifier names are return in canonical order, as
  125.      * specified by <em>The Java Language Specification<em>.
  126.      */
  127.     public static String toString(int mod) {
  128.     StringBuffer sb = new StringBuffer();
  129.     int len;
  130.  
  131.     if ((mod & PUBLIC) != 0)    sb.append("public ");
  132.     if ((mod & PRIVATE) != 0)    sb.append("private ");
  133.     if ((mod & PROTECTED) != 0)    sb.append("protected ");
  134.  
  135.     /* Canonical order */
  136.     if ((mod & ABSTRACT) != 0)    sb.append("abstract ");
  137.     if ((mod & STATIC) != 0)    sb.append("static ");
  138.     if ((mod & FINAL) != 0)        sb.append("final ");
  139.     if ((mod & TRANSIENT) != 0)    sb.append("transient ");
  140.     if ((mod & VOLATILE) != 0)    sb.append("volatile ");
  141.     if ((mod & NATIVE) != 0)    sb.append("native ");
  142.     if ((mod & SYNCHRONIZED) != 0)    sb.append("synchronized ");
  143.  
  144.     if ((mod & INTERFACE) != 0)    sb.append("interface ");
  145.  
  146.     if ((len = sb.length()) > 0)    /* trim trailing space */
  147.         return sb.toString().substring(0, len-1);
  148.     return "";
  149.     }
  150.  
  151.     /*
  152.      * Access modifier flag constants from <em>The Java Virtual
  153.      * Machine Specification</em>, Table 4.1.
  154.      */
  155.     public static final int PUBLIC           = 0x00000001;
  156.     public static final int PRIVATE          = 0x00000002;
  157.     public static final int PROTECTED        = 0x00000004;
  158.     public static final int STATIC           = 0x00000008;
  159.     public static final int FINAL            = 0x00000010;
  160.     public static final int SYNCHRONIZED     = 0x00000020;
  161.     public static final int VOLATILE         = 0x00000040;
  162.     public static final int TRANSIENT        = 0x00000080;
  163.     public static final int NATIVE           = 0x00000100;
  164.     public static final int INTERFACE        = 0x00000200;
  165.     public static final int ABSTRACT         = 0x00000400;
  166.  
  167. }
  168.